package edu.uni.dormitory.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.uni.dormitory.bean.LiveArea;
import edu.uni.dormitory.globalbean.AreaVo;
import edu.uni.dormitory.mapper.LiveAreaMapper;
import edu.uni.dormitory.service.AreaService;
import edu.uni.example.config.ExampleConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 陈楚城
 * @create 2019.05.03
 * @function 服务
 */
@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    private LiveAreaMapper liveAreaMapper;
    @Autowired
    private ExampleConfig globalConfig;

    /**
     * 新增宿舍区
     * @param liveArea
     * @return
     */
    @Override
    public boolean insert(LiveArea liveArea) {
        return liveAreaMapper.insert(liveArea)>0 ? true:false;
    }

    /**
     * 删除宿舍区
     * @param id
     * @return
     */
    @Override
    public boolean delete(long id) {
        return liveAreaMapper.deleteByPrimaryKey(id)>0 ? true:false;
    }

    /**
     * 修改宿舍区
     * @param liveArea
     * @return
     */
    @Override
    public boolean update(LiveArea liveArea) {
        return liveAreaMapper.updateByPrimaryKeySelective(liveArea)>0 ? true:false;
    }

    /**
     * 根据id查宿舍区
     * @param id
     * @return
     */
    @Override
    public AreaVo selectLiveArea(long id) {
        return liveAreaMapper.selectLiveArea(id);
    }

    /**
     * 分页查所有宿舍区信息
     * @param pageNum
     * @return
     */
    @Override
    public PageInfo<AreaVo> selectPage(Integer pageNum,long universityId) {
        PageHelper.startPage(pageNum, globalConfig.getPageSize());
        List<AreaVo> list = liveAreaMapper.selectAreaList(universityId);
        if(list != null)
            return new PageInfo<>(list);
        return null;
    }

    /**
     * 查询所有宿舍区信息
     * @return
     */
    @Override
    public List<AreaVo> selectAreaAll(long universityId) {
        return liveAreaMapper.selectAreaList(universityId);
    }

    /**
     * 根据宿管id查询宿舍信息
     * @param employeeId
     * @return
     */
    @Override
    public LiveArea selectAreaIdByEid(long employeeId) {
        return liveAreaMapper.selectAreaIdByEid(employeeId);
    }
}
